#ifndef NETWORKCLIENTCONNECTION_H
#define NETWORKCLIENTCONNECTION_H

#include <boost/thread.hpp>

#include "IConnection.h"
#include "network/ClientSession.h"

namespace ENE
{

class EventEngine;

class NetworkClientConnection : public IConnection
{
public:
	NetworkClientConnection();

	//Connecte le client au server
	void connect(const std::string& host, const std::string& port);

	//Demarre la partie reseau de la connection
	void start();

	//Envoie un event
	void sendEvent(boost::shared_ptr<const IGameEvent> event);

	//Definit le moteur d'evenement
	void setEventEngine(boost::shared_ptr<EventEngine> eventEngine);

	//!Retourne l'id du client
	Int8 getId() const;
	void setId(Int8 id);
private:
	void handleConnect(const boost::system::error_code& error);
	void handleHandshakeRead(const boost::system::error_code& error, const std::vector<Int8>& data);

	boost::asio::io_service m_ioService;
	ClientSession m_clientSession;
	boost::thread m_serviceThread;
	boost::shared_ptr<EventEngine> m_eventEngine;
	Int8 m_id;
};

}//namespace ENE

#endif

